package kd.hc.dev.tpl;

import kd.bos.context.RequestContext;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.events.HyperLinkClickArgs;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QFilter;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * 标准单据列表
 */
public class BosBillOrgTplExtListPlugin extends AbstractListPlugin implements Plugin {
    @Override
    public void setFilter(SetFilterEvent e) {
        super.setFilter(e);
    }

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        super.afterDoOperation(afterDoOperationEventArgs);
        String operateKey = afterDoOperationEventArgs.getOperateKey();
        if ("do_bath_update".equalsIgnoreCase(operateKey)) {
            ListSelectedRowCollection selectedRows = this.getSelectedRows();
            Set<Object> ids = new HashSet<>();
            for (int i = 0; i < selectedRows.size(); i++) {
                ListSelectedRow object = selectedRows.get(i);
                ids.add(object.getPrimaryKeyValue());
            }
            FormShowParameter showParameter = new FormShowParameter();
            showParameter.setCustomParam("title", "批量更新");
            showParameter.setFormId("hc95_batch_valueupdate");
            showParameter.getOpenStyle().setShowType(ShowType.Modal);
            showParameter.setCloseCallBack(new CloseCallBack(this, "batchUpdate"));
            this.getView().showForm(showParameter);
        }
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
        String actionId = closedCallBackEvent.getActionId();
        if (actionId.equals("batchUpdate")) {
            HashMap<String, String> returnData = (HashMap<String, String>) closedCallBackEvent.getReturnData();
            if (returnData != null) {
                String value = returnData.get("value");
                this.getView().showMessage("更新的值:" + value);
            }
            this.getView().invokeOperation("refresh");
        }
        super.closedCallBack(closedCallBackEvent);
    }


    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);

    }

    @Override
    public void itemClick(ItemClickEvent evt) {

        super.itemClick(evt);
    }

    @Override
    public void click(EventObject evt) {

        super.click(evt);
    }

    @Override
    public void billListHyperLinkClick(HyperLinkClickArgs args) {
        super.billListHyperLinkClick(args);
    }
}